#!/user/bin/even Python3
# -*- coding:utf-8 -*-
# PyInstallScript.py
# PyInstall程序打包脚本
# author:zhaohexin
# time：2020/5/28 10:22

import os

# 打包RunCase脚本 - 指定到指定位置 - 虚拟环境一定为 venv 文件夹
# 生成文件
# 获取工作目录
import subprocess

path = os.path.abspath(".")

# 打包页面脚本
UiStr = f"""
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['{os.path.join(path, 'Run.py')}'],
             pathex=[
             ],
             binaries=[
                ('{os.path.join(path, 'conf')}','conf'),
                ('{os.path.join(path, 'utility')}','utility'),
            ],
             datas=[],
             hiddenimports=['PyQt5.QtWidgets', "configobj"],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='LdlCodeSearch',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False )
""".replace('\\', '\\\\')
# 生成文件
with open(os.path.join(path, 'Ui.spec'), 'w', encoding="utf-8") as f:
    f.write(UiStr)
# 执行生成文件
p = subprocess.Popen(f"pyinstaller {os.path.join(path, 'Ui.spec')}", shell=True)
p.wait()

